import {Actions} from "react-native-router-flux";
import toast from "../component/common/ToastProxy";
import {string} from "prop-types";

export enum Code {
    NETWORK_ERROR = 1,
    NETWORK_TIMEOUT = 2,
    NETWORK_JSON_EXCEPTION = 3,
    SUCCESS = 200


}


export default function networkHandle(code, statusText?:string):boolean {
    if(code===Code.SUCCESS)return true;
    switch (code) {
        case 401:
            toast("未授权或授权失败！");
            break;
        case 403:
            toast("没有网络权限！");
            break;
        case 404:
            toast("404,请求错误!");
            break;
        case 410:
            toast("410,请求错误！");
            break;
        case Code.NETWORK_TIMEOUT:
            //超时
            toast("请求超时！");
            break;
        default:
            if (statusText) {
                toast(statusText);
            } else {
                toast("未知错误！");
            }
            break;
    }
    return false;

}